package com.cmty256.cmuser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author chenmeng
 */
@SpringBootApplication
public class CmUserApplication {

    private static final Logger LOG = LoggerFactory.getLogger(CmUserApplication.class);

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(CmUserApplication.class);
        Environment env = app.run(args).getEnvironment();
        String applicationName = env.getProperty("spring.application.name");
        String profile = env.getProperty("spring.profiles.active");
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        // 获取服务器的Scheme（HTTP或HTTPS）
        String scheme = "true".equals(env.getProperty("server.ssl.enabled", "false")) ? "https" : "http";

        String localUrl = "http://127.0.0.1:" + port + path;
        String networkUrl = scheme + "://" + ip + ":" + port + path;
        String swaggerDocUrl = scheme + "://" + ip + ":" + port + path + "/doc.html";
        String res = "\n----------------------------------------------------------"
                + "\n\t[" + applicationName + ": " + profile + "], 启动成功！！！"
                + "\n\t" + "Local: " + localUrl
                + "\n\t" + "Network: " + networkUrl
                + "\n\t" + "Swagger Doc:: " + swaggerDocUrl
                + "\n----------------------------------------------------------";
        LOG.info(res);
    }
}
